#ifndef __RENDERER_H__
#define __RENDERER_H__

#include "HandModel.h"
#include <vector>
#include "opencv2/opencv.hpp"

//#define PERFORMANCE_TEST

enum RenderMode
{
	DRAW_CROP_128,
	DRAW_FULL_COLOR
};

/* A class manage on creating OPENGL context and drawing hypothesis depth map  */
class GLRenderer
{
public:
	GLRenderer();
	~GLRenderer();

	HandModel rHand;
	GLFWwindow * pWindow;

	int data_width;
	int data_height;
	int particle_data_width;
	int particle_data_height;

	void initialize(GLFWwindow * window, RenderMode mode);

	GLuint obsDepthBuffer;
	GLuint obsSkinBuffer;
	GLuint renBuffer;

	GLuint frameBuffer,renderFrameBuffer;
	GLuint half_FBO,half_RBO;

	//GLuint depth_tex2d,color_tex2d;
	//GLuint obsDepth_tex2d,obsSkin_tex2d;

	void rendering();
	void renderHandModelGL();
	void renderMultiModelGL(std::vector<float*> &hypos);
	void putDepthToBuf(GLuint & buffer);

	void calculatingHandCenter(cv::Point3f handCenter);
private:
	GLfloat	frustum_near;
	GLfloat	frustum_far;

	GLfloat	frustum_focal_mm;
	GLfloat	frustum_far_mm;

	GLint		screenWidth;
	GLint		screenHeight;

	RenderMode	renderMode;

	void prepareValuesForMode();
	void initializePixelBufs();

	Eigen::Matrix4f matrixFrustum;
	Eigen::Matrix4f matrixFrustum_focus;
	
	void frustumMat(GLint left, GLint right, GLint bottom, GLint top, GLfloat zNear, GLfloat zFar);	
};

#endif